var api = require('../../../config/api.js');
var util = require('../../../utils/util');
Page({

    /** 
     * 页面的初始数据
     */
    data: {
        money: 0,
        price: '',
        bandCard: '',
        remark: '',
        realName: '',
        userId: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            money: options.money,
            userId: options.userId
        })
    },

    allWith() {
        let money = this.data.money
        this.setData({
            price: money
        })
        console.log(this.data.price)
    },
    userInput(event) {
        const value = event.detail.value;
        this.setData({
            price: value
        })
    },
    realNameValue(event) {
        const value = event.detail.value;
        console.log(value, 'value')
        this.setData({
            realName: value
        })
    },
    remarkValue(event) {
        const value = event.detail.value;
        this.setData({
            remark: value
        })
    },
    bandCardValue(event) {
        const value = event.detail.value;
        this.setData({
            bandCard: value
        })
    },
    withUserMoney() {
        let that = this
        let { userId, price, bandCard, realName, remark } = that.data
        if (!realName) {
            wx.showToast({
                icon: 'error',
                title: '请输入姓名'
            })
            return
        }
        if (!bandCard) {
            wx.showToast({
                icon: 'error',
                title: '请输入卡号'
            })
            return
        }
        if (!remark) {
            wx.showToast({
                icon: 'error',
                title: '请输入开户行'
            })
            return
        }
        if (price == '' || price < 0) {
            wx.showToast({
                icon: 'error',
                title: '请输入提现金额'
            })
            return
        }
        wx.showModal({
            title: '温馨提示',
            content: `确定提现${that.data.price}到银行`,
            success(res) {
                if (res.confirm) {
                    util.request(api.withAdd, { userId, price, bandCard, realName, remark }, 'post').then(res => {
                        if (res.errno === 0) {
                            wx.showToast({
                                title: '成功',
                                icon: 'success',
                                duration: 2000
                            })
                            wx.navigateBack({
                                delta: 1
                            })
                        }
                    })
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})